﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class PreUnaryExpression : PreExpression
{
    private readonly SourceNode _operatorToken;
    private PreExpression _expression;

    internal PreUnaryExpression(SourceNode? parent, SourceNode operatorToken, PreExpression expression) :
        base(parent, SyntaxKinds.UnaryExpression)
    {
        SetChildField(ref _operatorToken, operatorToken);
        SetChildField(ref _expression, expression);
    }


    public SourceNode OperatorToken => _operatorToken;

    public PreExpression Expression => _expression;


    public PreUnaryExpression Update(PreExpression expression)
    {
        SetChildField(ref _expression, PreEmptyExpression.IsNullOrDefaultEmptyExpression, expression);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, OperatorToken, Expression);
    }
}


public static partial class NodeFactory
{
    public static PreUnaryExpression CreatePreUnaryExpression(SourceNode? parent,
        SourceNode operatorToken, PreExpression expression)
    {
        Debug.Assert(operatorToken.IsPreUnaryOperator);
        return new PreUnaryExpression(parent, operatorToken, expression);
    }
}